﻿using DotNetCore.CAP;
using Ebusiness_ProductService.Services;
using Ebusiness_ProductService.Services.Dtos.Product;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.Application.Dtos;
using Volo.Abp.AspNetCore.Mvc;

namespace Ebusiness_WebSites.Controllers
{
    [Route("Product/[controller]")]
    [ApiController]
    public class ProductController : AbpController
    {
        public IProductService productService { get; set; }

        public ILogger<ProductController> logger { get; set; }

        /// <summary>
        /// 事件发送接口
        /// </summary>
        public ICapPublisher capPublisher { set; get; }

        public ProductController()
        {

        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PagedResultDto<ProductDto>> GetListAsync(PagedAndSortedResultRequestDto input)
        {
            logger.LogInformation("代码没报错");
            logger.LogError("代码报错啦");
            return await productService.GetListAsync(input);
        }

        /// <summary>
        /// 发送添加商品事件给CAP
        /// </summary>
        /// <returns></returns>
        [HttpPost("AddProduct")]
        public async Task<string> AddProduct(ProductDto  productDto) 
        {
            logger.LogInformation("代码没报错");
            logger.LogError("代码报错啦");
            // 1、发送添加商品事件给CAP
            capPublisher.Publish<ProductDto>("AddProduct", productDto);
            return "添加成功";
        }
    }
}
